package com.bw.controller;

import com.bw.entity.TbDing;
import com.bw.service.DefinitionService;
import javax.servlet.http.HttpServletRequest;

import com.bw.vo.TbDingYi;
import com.bw.vo.TbType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class DefinitionController {

    @Autowired
    private DefinitionService studentService;

//      @RequestMapping("tologin")
//      public String tologin(){
//          return "login";
//      }
//
//      @PostMapping("login")
//      public String index(@RequestBody TbUser tbuser){
//          TbUser tbUser = studentService.login(tbuser);
//          if(tbUser!=null){
//              return "ok";
//          }
//          return "no";
//      }
      @GetMapping("dingyiList")
      public List<TbDingYi> dingyiList(HttpServletRequest request,@RequestParam(value = "mohu",defaultValue = "")String mohu){
          List<TbDingYi> dingyiList = studentService.dingyiList(mohu);
          request.setAttribute("dingyiList",dingyiList);
          return dingyiList;
      }

      @GetMapping("update")
      public String update(int id){
          TbDing tbDing = studentService.update(id);
          return "redirect:dingyiList";
      }

    @GetMapping("typeList")
    public List<TbType> typeList(HttpServletRequest request, @RequestParam(value = "mohu",defaultValue = "")String mohu){
        List<TbType> typeList = studentService.typeList(mohu);
        request.setAttribute("typeList",typeList);
        return typeList;
    }

    @GetMapping("findBytype")
    public TbType findBytype(int id){
        TbType tbType = studentService.findBytype(id);
        return tbType;
    }
    @GetMapping("findBydingyi")
    public TbDingYi findBydingyi(int id){
        TbDingYi TbDingYi = studentService.findBydingyi(id);
        return TbDingYi;
    }

    @PostMapping("updateBytype")
    public void updateBytype(@RequestBody TbType tbType){
        studentService.updateBytype(tbType);
    }

    @PostMapping("updateBydingyi")
    public void updateBydingyi(@RequestBody TbDing tbDing){
        studentService.updateBydingyi(tbDing);
    }
    @PostMapping("updateBydingyiId")
    public void updateBydingyiId(@RequestParam("ids")String ids){
        String[] id = ids.split(",");
        for (String aa:id){
            studentService.updateBydingyiId(aa);
        }
    }
    @PostMapping("updateBydingyiIdd")
    public void updateBydingyiIdd(@RequestParam("ids")String ids){
        String[] id = ids.split(",");
        for (String aa:id){
            studentService.updateBydingyiIdd(aa);
        }
    }

    @PostMapping("addBytype")
    public void addBytype(@RequestBody TbType tbType){
        studentService.addBytype(tbType);
    }
    @PostMapping("dingyiadds")
    public void dingyiadds(@RequestBody TbDing TbDing){
        studentService.dingyiadds(TbDing);
    }
    @GetMapping("deldingyi")
    public void deldingyi(@RequestParam("ids") String ids){
          String[] id = ids.split(",");
          for (String aa:id){
              studentService.deldingyi(aa);
          }

    }
    @GetMapping("deltype")
    public void deltype(@RequestParam("ids") String ids){
          String[] id = ids.split(",");
          for (String aa:id){
              studentService.deltype(aa);
          }

    }

}
